﻿using AutoMapper;
using MediatR;
using SheepStorage.API.Application.Command.YourTableNameCommand;
using SheepStorage.API.Baseclass;
using SheepStorage.Domain.Entity;
using SheepStorage.Service.DataImp;
using SheepStorage.Service.Interface;

namespace SheepStorage.API.Application.CommandHandler
{
    public class YourTableNameAddCommandHandler : IRequestHandler<YourTableNameAddCommand, Results<int>>
    {


        private readonly IYourTableNameService _yourTableNameService;
        private readonly IMapper _mapper;
        public YourTableNameAddCommandHandler(IYourTableNameService yourTableNameService, IMapper mapper)
        {
            _yourTableNameService = yourTableNameService;
            _mapper = mapper;
        }

        public async Task<Results<int>> Handle(YourTableNameAddCommand request, CancellationToken cancellationToken)
        {
            var result = _mapper.Map<List<YourTableName>>(request.BeginnList);

            return Results<int>.DataResult(await _yourTableNameService.AddYourTableNames(result));
        }
    }
}
